#include<stdio.h>
#include<string.h>

#define N 20

struct mart{
    char name[10];//商品名
    char market[10];//超市名
    float pri;//价格
    int count;//打折
}a[N];


char code[6]; //密码
char mail[50];//邮箱***@***.***
char address[50]; //地址
double phone; //电话号码11位


struct mart a[N]={{"牛奶","Auchan",3.2,1},{"water","Wumart",2,0}};

void find_n(char s[],int n)//查询商品
{
    int flag = 0;
    for(int i=0;i<n;i++)
    {
        if(!strcmp(s,a[i].name))
        {
            printf("%d\t商品名：%s\t价格：%.2f\n",i+1,a[i].name,a[i].pri);
            flag = 1;
            break;
        }

    }
    if (!flag)  printf("未找到！");
}

void find_m(char m[],int n)//查询超市
{
    int flag = 0;
    for(int i=0;i<n;i++)
    {
        if(!strcmp(m,a[i].market))
        {
            printf("%d\t商品名：%s\t价格：%.2f\n",i+1,a[i].market,a[i].pri);
            flag = 1;
            break;
        }

    }
    if (!flag)  printf("未找到！");
}

void all(int n)//显示全部商品
{
    for(int i=0;i<n;i++)
    {
        printf("%d\t商品名：%s\t价格：%.2f\n",i+1,a[i].name,a[i].pri);
    }
}

void count(int n)
{
    for(int i=0;i<n;i++)
    {
        if(a[i].count)//有折扣是1，没折扣是0
            printf("%d\t商品名：%s\t价格：%.2f\n",i+1,a[i].name,a[i].pri);
    }
}

void change()//修改顾客信息
{
    int v;
    printf("wich part of your personal information do you want to adjust? \n");
    printf("1 password\n2 mail address\n3 phone number\n4 address\n0 exit\n");
    scanf("%d",&v);
    switch(v)
    {
        case 1:
            printf("Please enter your new password \n");
            scanf("%s", code);
            break;

        case 2:
            printf("Please enter your new mail address \n");
            scanf("%s", mail);
            break;

        case 3:
            printf("Please enter your new phone number \n");
            scanf("%lf", phone);
            break;

        case 4:
            printf("Please enter your new address\n");
            scanf("%s", address);
            break;

        case 0:
            break;
    }

}

int main(){

    int t,n = 2;//n为商品数量，整合时可以导入相关数据
    char y;
    char s[10];//商品名称
    char m[10];//超市名称


    while(1)
    {
        printf("1 查询商品\n2 查询超市\n3 查看全部\n4 查询折扣\n5 修改个人信息\n0 退出系统\n");//整合时可以借鉴商品录入的界面
        scanf("%d",&t);

        if(t<1)     break;

        switch(t)
        {
            case 1:

                while(1)
                {
                    printf("输入品名：");
                    scanf("%s",s);
                    find_n(s, n);
                    printf("是否继续搜索（y/n)：");
                    scanf("\n%c", &y);
                    if (y =='n')
                        break;
                }
                break;

            case 2:
                printf("输入超市名：");
                scanf("%s",m);
                find_m(m,n);
                break;

            case 3:
                all(n);
                break;

            case 4:
                printf("有折扣的商品:");
                count(n);
                break;

            case 5:
                change();
                break;

        }
    }

    return 0;

}
